package cn.ezios.huo.system.biz.controller;

import cn.ezios.huo.system.dao.domain.SysDictCatalog;
import cn.ezios.huo.system.dao.dto.SysDictCatalogDTO;
import cn.ezios.huo.system.dao.vo.SysDictCatalogVO;
import cn.ezios.huo.system.dao.service.SysDictCatalogService;
import cn.ezios.huo.common.mvc.Ret;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("sys/dict/catalog")
@RequiredArgsConstructor
public class SysDictCatalogController {

    private final SysDictCatalogService sysDictCatalogService;

    @PostMapping("")
    public Ret add(@RequestBody SysDictCatalog sysDictCatalog) {
        boolean save = sysDictCatalogService.save(sysDictCatalog);
        return save ? Ret.ok() : Ret.error();
    }

    @PutMapping("")
    public Ret update(@RequestBody SysDictCatalog sysDictCatalog) {
        boolean update = sysDictCatalogService.updateById(sysDictCatalog);
        return update ? Ret.ok() : Ret.error();
    }

    @GetMapping("{id}")
    public Ret get(@PathVariable("id") String id) {
        SysDictCatalog sysDictCatalog = sysDictCatalogService.getById(id);
        return sysDictCatalog != null ? Ret.ok(sysDictCatalog) : Ret.error("未找到");
    }

    @GetMapping("page")
    public Ret page(@RequestParam(value = "current", defaultValue = "1") Integer current,
    @RequestParam(value = "size", defaultValue = "10") Integer size,SysDictCatalogDTO dto) {
       IPage <SysDictCatalogVO> page = sysDictCatalogService.queryPage(current,size,dto);
            return Ret.ok(page);
    }

    @DeleteMapping("{id}")
    public Ret delete(@PathVariable("id") String id) {
        boolean remove = sysDictCatalogService.removeById(id);
        return remove ? Ret.ok() : Ret.error();
    }
}
